package day_2022_4_to_7.day48;

import java.util.Scanner;

/**
 * 两种排序方法
 * @author haomin
 * @date 2022/04/26 14:27
 **/
public class Day8_1_TwoSortByLenAndLet {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] arr = new String[n];
        for(int i = 0;i < n;i++){
            arr[i] = in.next();
        }
        boolean judgeLength = judgeLengthHelper(arr,n);
        boolean judgeLetter = judgeLetterHelper(arr,n);
        printfHelper(judgeLength,judgeLetter);
    }

    private static void printfHelper(boolean len, boolean let) {
        if(len == true && let == true){
            System.out.println("both");
        }
        else if(len == true){
            System.out.println("lengths");
        }
        else if(let == true){
            System.out.println("lexicographically");
        }
        else {
            System.out.println("none");
        }
    }

    // 判断字母
    private static boolean judgeLetterHelper(String[] arr, int n) {
        for (int i = 0; i < n-1; i++) {
            if(compareHelper(arr[i],arr[i+1]) > 0){
                return false;
            }
        }
        return true;
    }

    private static int compareHelper(String s1, String s2) {
        int minLen = Math.min(s1.length(),s2.length());
        char[] s1Char = s1.toCharArray();
        char[] s2Char = s2.toCharArray();
        int k = 0;
        while (k < minLen){
            char a = s1Char[k];
            char b = s2Char[k];
            if(a != b){
                return a - b;
            }
            k++;
        }
        return s1.length() - s2.length();
    }

    // 判断长度
    private static boolean judgeLengthHelper(String[] arr, int n) {
        for (int i = 0; i < n-1; i++) {
            if(arr[i].length() > arr[i+1].length()){
                return false;
            }
        }
        return true;
    }
}